const { Proxy } = require("./src/config");
const args = process.argv.slice(3)
  .map(e => e.replace(/-/g, ''))
  .map(e => e.split('='))
  .reduce((acu, [key, value]) => (acu[key] = value || true, acu), {});
process.env.VUE_APP_PLATFORM = args.platform || 'web';
process.env.VUE_APP_DEBUG = args.debug || "";
process.env.VUE_APP_LOG = args.log || "";
module.exports = {
  publicPath: process.env.NODE_ENV === 'development' ? '/' : './',
  productionSourceMap: false,
  devServer: {
    port: 8081,
    proxy: {
      '/DEV/*': {
        target: Proxy.DEV,
        pathRewrite: {
          '^/DEV': '',
        }
      },
      '/TEST/*': {
        target: Proxy.TEST,
        pathRewrite: {
          '^/TEST': '',
        }
      },
      '/RELEASE/*': {
        target: Proxy.RELEASE,
        pathRewrite: {
          '^/RELEASE': '',
        }
      }
    }
  },
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        args[0].title = '易拉罐';
        return args;
      })
  },
  configureWebpack: config => {
    config.module.rules.filter(rule => {
      return rule.test.toString().indexOf("scss") !== -1;
    })
      .forEach(rule => {
        rule.oneOf.forEach(oneOfRule => {
          oneOfRule.use.splice(oneOfRule.use.indexOf(require.resolve('sass-loader')), 0,
            { loader: require.resolve("css-unicode-loader")})
        })
      })
  }
}

